import { getGameObjectById } from "../engine";
import { Behaviour } from "../engine/Behaviour";
import { Transform } from "../engine/Transform";
import { number } from "../engine/validators/number";
import { AnimationBehaviour } from "./AnimationBehaviour";
import { RigidBody } from "./RigidBody";
import { Sound } from "./sound";

export class Jumpable extends Behaviour {
    
    private isJump = false;
    @number()
    speed = 1;

    onStart() {
        const rigid = this.gameObject.getBehaviour(RigidBody);
        window.addEventListener('keypress', (e) => {
            if(getGameObjectById('PauseBackGround')===undefined){
            if(e.key==='w'||e.key==='W'){
                if(this.isJump===false){
                    rigid.b2RigidBody.SetLinearVelocity({ x: 0, y: this.speed })
                    const ani= getGameObjectById('Alice');
                    const animationBehaviour=ani.getBehaviour(AnimationBehaviour);
                    animationBehaviour.action='rightjump'
                }

            }}
            else{
                if(getGameObjectById('PauseBackGround').active===true){


                }
                else{
                    if(e.key==='w'||e.key==='W'){
                        if(this.isJump===false){
                            rigid.b2RigidBody.SetLinearVelocity({ x: 0, y: this.speed })
                            const ani= getGameObjectById('Alice');
                            const animationBehaviour=ani.getBehaviour(AnimationBehaviour);
                            animationBehaviour.action='rightjump'
                        }
                    }
                }   
            }
         })

         window.addEventListener('keyup', (e) => {
            if(e.key==='w'||e.key==='w'){
                const ani=getGameObjectById('Alice');
                const animationBehaviour=ani.getBehaviour(AnimationBehaviour);
                animationBehaviour.action='rightdrop'
                rigid.b2RigidBody.SetLinearVelocity({ x: 0, y: 0 })
            }

         })
    }

}
